package com.example.controller;


import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RefreshScope
@RequestMapping("/main")
public class UserController {

    @Autowired
    private RedisTemplate redisTemplate;

    @Value("${text.demo}")
    private String test;

    @GetMapping("/config")
    public String config(){
        return test;
    }

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/test")
    public void testSendMessage(){
        String queueNme = "simple.queue";
        String message = "hello, spring amqp";
        System.out.println("fwcg");
        rabbitTemplate.convertAndSend(queueNme,message);
    }
    @GetMapping("/test1")
    public void testSendMessage1(){
        String queueNme = "object.queue1";
        Map<String,Object> message = new HashMap<>();
        message.put("name","罗钦盛");
        message.put("age",12);
        System.out.println("fwcg");
        rabbitTemplate.convertAndSend(queueNme,message);
    }
    @GetMapping("/test2")
    public void testSendMessage2(){
        String queueNme = "simple.queue";
        String message = "hello, spring amqp";
        for (int i = 0; i < 50; i++) {
            rabbitTemplate.convertAndSend(queueNme,message+"["+i+"]");
        }
    }


    @GetMapping("/test3")
    public void testSendMessage3(){
        String exChange = "itcast.fanout";
        String message = "hello,ervery";
        System.err.println("-----------------");
            rabbitTemplate.convertAndSend(exChange,"",message);
    }

    @GetMapping("/test4/{key}")
    public void testSendMessage4(@PathVariable("key")String key){
        String exChange = "itcast.direct";
        String message = "hello,ervery";

        rabbitTemplate.convertAndSend(exChange,key,message);
    }

    @GetMapping("/test5/{key}")
    public void testSendMessage5(@PathVariable("key")String key){
        String exChange = "itcast.topic";
        String message = "hello,ervery";

        rabbitTemplate.convertAndSend(exChange,key,message);
    }
}
